/**
 * 
 */
package com.wubo.sec.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;

/**
 * 登录入口
 * @author WuBo
 * @CreateDate 2012-2-15
 */
public class LoginEntryPoint extends LoginUrlAuthenticationEntryPoint implements AuthenticationEntryPoint {
	/**当请求是AJAX请求时对应的登录处理ACTION*/
	public final static String SCRIPT_REQUEST_ACTION = "/toScriptLogin.action";
	
	private String scriptRequestAction = SCRIPT_REQUEST_ACTION;
	
	public LoginEntryPoint(){
		super(UserLoginPageHelper.DEFAULT_LOGIN_PAGE);
	}
	
	 protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response,
	            AuthenticationException exception) {
		 if(UserLoginPageHelper.isScriptRequest(request)){
			 return getScriptRequestAction();
		 }
		 
		 return UserLoginPageHelper.getLoginPageUrl(request);
    }

	public String getScriptRequestAction() {
		return scriptRequestAction;
	}

	public void setScriptRequestAction(String scriptRequestAction) {
		this.scriptRequestAction = scriptRequestAction;
	}

}
